﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class my_subscribe_city : System.Web.UI.Page
{

    ctpDataContext db;
    int no;

    protected void Page_Load(object sender, EventArgs e)
    {
        db = new ctpDataContext();

         no =(int) Session["userno"];

        if (!this.IsPostBack)
        {

            mybind();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        my_citiport_subscribe s = db.my_citiport_subscribes.Single(p => p.no ==int.Parse( this.ListBox1.SelectedValue));

        my_citiport_mine m = db.my_citiport_mines.Single(p => p.no == s.subscribe_ct_no);
        m.recommend -= 1;

        db.my_citiport_subscribes.DeleteOnSubmit(s);
        db.SubmitChanges();



        this.mybind();

        if (this.ListBox1.Items.Count != 0)
            this.ListBox1.Items[0].Selected = true;


    }

    void mybind()
    {

        var si = from p in db.my_citiport_subscribes
                 join q in db.my_citiport_mines on p.subscribe_ct_no equals q.no
                 join i in db.users on q.userno equals i.no
                 join j in db.ct_profiles on q.ct_no equals j.no
                 where p.userno == no
                 orderby p.addtime descending
                 select new
                 {
                     title = i.nickname.Trim().Replace(",", "") + " - " + j.title.Trim().Replace(",", ""),
                     p.no,



                 };

        this.ListBox1.DataSource = si;
        this.ListBox1.DataTextField = "title";
        this.ListBox1.DataValueField = "no";

        this.DataBind();
    }


    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
